-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add example code for each configuration to verify correctness during continuous integration #12
Add example code for each configuration to verify correctness during continuous integration #12
Conversation
…continuous integration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some notes for context:
## 1.2.0 | ||
|
||
- Testing added using example code for each configuration to verify correctness during continuous integration | ||
- React and Preact TypeScript configs now allow JSX in files with `.tsx` file extensions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This improvement resulted from writing the tests
@@ -20,7 +20,7 @@ | |||
|
|||
"overrides": [ | |||
{ | |||
"files": "*.{cjs,js,jsx,mjs,ts,tsx}", | |||
"files": "*.{cjs,cts,js,jsx,mjs,mts,ts,tsx}", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was originally using .mts
files when I started this work. I started off using Bun to write unit tests then settled on using example code and running ESLint against it because it was more informative and easier to identify the root cause of errors.
@@ -9,5 +9,7 @@ | |||
"browser": false, | |||
"node": false | |||
}, | |||
"rules": {} | |||
"rules": { | |||
"react/jsx-filename-extension": ["error", { "extensions": [".jsx", ".tsx"] }] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the improvement to the library that resulted from testing. The Preact Typescript config extends this config so it benefits from this too.
"@playwright/test": "1.40.1", | ||
"@types/aws-lambda": "8.10.131", | ||
"@types/node": "20.10.6", | ||
"@types/react": "18.2.46", | ||
"@types/react-dom": "18.2.18", | ||
"eslint": "8.56.0", | ||
"jest": "29.7.0", | ||
"preact": "10.19.3", | ||
"prettier": "3.1.0", | ||
"prop-types": "15.8.1", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"typescript": "5.3.3" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only added dev dependencies necessary for these tests. I'll update non-dev dependencies in a separate PR to bring them up to their latest versions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was a huge time investment because every config extends from this one. I went one-by-one through every rule and tried to write code to tackle each, but it wasn't always possible. The most targeted rules ended up being the regex and unicorn ones.
[ssr] | ||
maintained Node versions |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
During this process, I learned you can target SSR separately using Browserslist. Food for thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might look familiar 🙃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because I was running low on time, I adapted the same example for the Preact, Preact TypeScript, React, and React TypeScript tests
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Really nice work!
I think the last test examples are more similar to what I had imagined, basically they just allow to test that the config works overall (e.g. the eslint config is valid, it doesn't have broken parts and we can run it an ESLint check with it successfully).
The other one is interesting as it could give more safety, but I think it's quite hard to make it work correctly and maintain, so it might not be worth it I think.
Approving regardless of what we decide on the base tests, as ultimately I think they still do the job even though they might be a bit too complex or not necessarily 100% fulfilling their intended goals.
objectWithSortedKeys, | ||
oneThousand, | ||
printEslintConfig, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Quite thorough work here, but I am not sure whether this actually tests the rule.
As an example, if I were to remove the rule unicorn/prefer-node-protocol
, tests for this file would still pass, because it wouldn't break any new rules.
I guess one way we could check for those could be by disabling things, and then as long as we have "report unused disables", we would get warned in case something goes wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yea this is a drawback to this approach. I had originally started with the ESLint API directly to be able to catch some negative cases (e.g. if a rule is disabled), but the way it reports back problems isn't very friendly so when I extrapolated the amount of work necessary to make it maintainable and easily understandable, I decided to just use the CLI which is far more friendly and what people are used to. Not perfect but a lot better than what was there before.
} | ||
|
||
// Begin Execution | ||
main(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this file I can see you haven't specified which rules different parts of the code tests, is that intentional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mostly did that for the base config, then when I was time boxing I wasn't as thorough. Apparently I didn't add any here.
Pull Request Checklist
package.json
andpackage-lock.json
following Semantic VersioningChanges Included
1.2.0
.tsx
file extensionsnpm-run-all
because it was only used during thereinstall
NPM script and would cause an error if dependencies weren't installed prior to execution